package com.linpq.road.controller;

import java.util.List;

import com.linpq.road.domain.Roadsection;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdHighSpeedRoad;
import com.linpq.road.service.RdHighSpeedRoadService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 高速公路Controller
 *
 * @author linpq
 * @date 2021-07-28
 */
@Controller
@RequestMapping("/road/high_speed_road")
public class RdHighSpeedRoadController extends BaseController {
    private String prefix = "road/high_speed_road";

    @Autowired
    private RdHighSpeedRoadService rdHighSpeedRoadService;

    @RequiresPermissions("road:high_speed_road:view")
    @GetMapping()
    public String high_speed_road() {
        return prefix + "/high_speed_road";
    }

    /**
     * 查询高速公路列表
     */
    @RequiresPermissions("road:high_speed_road:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdHighSpeedRoad rdHighSpeedRoad) {
        startPage();
        List<RdHighSpeedRoad> list = rdHighSpeedRoadService.selectRdHighSpeedRoadList(rdHighSpeedRoad);
        return getDataTable(list);
    }

    /**
     * 查询所有高速公路
     * @return
     */
    @GetMapping("/findAll")
    @ResponseBody
    public List<RdHighSpeedRoad> findAll(){
        List<RdHighSpeedRoad> rdHighSpeedRoadList = rdHighSpeedRoadService.findList(null);
        return  rdHighSpeedRoadList;
    }


    /**
     * 导出高速公路列表
     */
    @RequiresPermissions("road:high_speed_road:export")
    @Log(title = "高速公路", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdHighSpeedRoad rdHighSpeedRoad) {
        List<RdHighSpeedRoad> list = rdHighSpeedRoadService.selectRdHighSpeedRoadList(rdHighSpeedRoad);
        ExcelUtil<RdHighSpeedRoad> util = new ExcelUtil<RdHighSpeedRoad>(RdHighSpeedRoad.class);
        return util.exportExcel(list, "high_speed_road");
    }

    /**
     * 新增高速公路
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存高速公路
     */
    @RequiresPermissions("road:high_speed_road:add")
    @Log(title = "高速公路", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdHighSpeedRoad rdHighSpeedRoad) {
        return toAjax(rdHighSpeedRoadService.insertRdHighSpeedRoad(rdHighSpeedRoad));
    }

    /**
     * 修改高速公路
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdHighSpeedRoad rdHighSpeedRoad = rdHighSpeedRoadService.selectRdHighSpeedRoadById(id);
        mmap.put("rdHighSpeedRoad", rdHighSpeedRoad);
        return prefix + "/edit";
    }

    /**
     * 修改保存高速公路
     */
    @RequiresPermissions("road:high_speed_road:edit")
    @Log(title = "高速公路", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdHighSpeedRoad rdHighSpeedRoad) {
        return toAjax(rdHighSpeedRoadService.updateRdHighSpeedRoad(rdHighSpeedRoad));
    }

    /**
     * 删除高速公路
     */
    @RequiresPermissions("road:high_speed_road:remove")
    @Log(title = "高速公路", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdHighSpeedRoadService.deleteRdHighSpeedRoadByIds(ids));
    }
}
